package coop.bancocredicoop.proyectos.gd;

import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;

public class FrontEndMessage {

	private List<String> errorMessages;
	private String successMessage;
	
	public FrontEndMessage() {
		errorMessages = new ArrayList<String>();
		successMessage = null;
	}
	
	public void setSuccessMessage(String message) {
		successMessage = message;
	}
	
	public String getSuccesMessage() {
		return successMessage;
	}
	
	public void addErrorMessage(String message) {
		errorMessages.add(message);
	}
	
	public Iterator<String> getErrorMessages() {
		return errorMessages.iterator();
	}
	
	public boolean hasErrors() {
		return !errorMessages.isEmpty();
	}
	
	public void setMessagesInSession(HttpServletRequest request) {
		HttpSession session = request.getSession();
		session.setAttribute("hasErrors", hasErrors());
		session.setAttribute("errorMessages", getErrorMessages());
		session.setAttribute("successMessage", getSuccesMessage());		
	}
	
}
